package org.example.likou150.array;

/*
* https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-interview-150
* */
public class MaxArea {
    public int maxArea(int[] height) {
        int maxArea=Integer.MIN_VALUE;
        int left = 0;
        int right = height.length-1;
        while(left < right){
            int minHeight = Math.min(height[left], height[right]);
            maxArea = Math.max(maxArea, minHeight*(right-left));
            while(left < right && height[left] <= minHeight){
                left++;
            }
            while(left < right && height[right] <= minHeight){
                right--;
            }
        }
        return maxArea;
    }
}
